Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

344
Views
Angular - How to call ngOnDestroy when change [src] in iFrame

I have one slide show application that support only many internal link.

HTML

<iframe width="100%" id="iframeSlide" height="100%" #iframe frameBorder="0" [src]="urlSafe"></iframe>

TS code

current.urlSafe = current.sanitizer.bypassSecurityTrustResourceUrl(current.slideUrls[current.index]);

slideUrls is an array contains list of internal link, but when new url set to current.urlSafe, the old url did not call ngOnDestroy function to release resource.

I tried to set current.urlSafe = "about:blank";

or

var frame = document.getElementById("iframeSlide"),
frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.removeChild(frameDoc.documentElement);

But it did not call ngOnDestroy function. In the internal page, I used setInterval function so need go to ngOnDestroy to clear the Interval, without it many request to called inside setInterval.

Links I refereed

https://web.dev/detached-window-memory-leaks/

How do I clear all intervals?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Changing the iframe src would be the equivalent to navigating to a new url in the browser address bar. The browser itself clears the top level JS/HTML resources in this case

ngOnDestroy would occur if you remove components or services within the app, but not on a refresh

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!